package metro.cards;


import metro.cards.types.CardType;
import metro.response.Response;
import metro.system.MetroSystem;
import metro.tourniquet.Tourniquet;

import java.util.Calendar;

public class MoneyCard extends Card {
    private int balance;

    protected MoneyCard(Calendar creationDate,int balance) {
        this(creationDate);
        this.balance = balance;

    }

    protected MoneyCard(Calendar creationDate) {
        super(creationDate);
        balance =0;
        type= CardType.MONEY_CARD;
    }

    public static MoneyCard createFiftyDollarsCard(Calendar creationDate){
        return new MoneyCard(creationDate,50*100);
    }

    public static MoneyCard createHundredDollarsCard(Calendar creationDate){
        return new MoneyCard(creationDate,100*100);
    }

    public static MoneyCard createEmptyDollarsCard(Calendar creationDate){
        return new MoneyCard(creationDate);
    }

    public void updateBalance(int value){
        if (value<0)
            throw new IllegalArgumentException();
        balance+=value;
    }

    public int getBalance() {
        return balance;
    }

    public String balanceToString(){
        return "$"+balance/100+"."+balance%100;
    }

    @Override
    public Response use(MetroSystem system,Tourniquet tourniquet) {
        if (system.getCost()<= balance){
            balance -=system.getCost();
            return Response.createPositiveMoneyResponse(this,tourniquet);
        } else
            return Response.createNegativeMoneyResponse(this,tourniquet);
    }
}
